package com.bjfu.gmms.servlet;

import com.bjfu.gmms.MyBatisUtil;
import com.bjfu.gmms.mapper.ExamScoreMapper;
import com.bjfu.gmms.mapper.MentorMapper;
import com.bjfu.gmms.model.Mentor;
import com.google.gson.Gson;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getMentors")
public class GetMentorsServlet extends HttpServlet {
    private MentorMapper mentorMapper;

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String researchId = request.getParameter("researchId");
        System.out.println(researchId);
        SqlSession sqlSession = MyBatisUtil.getSqlSession("development");
        mentorMapper = sqlSession.getMapper(MentorMapper.class);
        // 查询研究方向对应的导师列表
        List<Mentor> mentors = mentorMapper.getMentorsByResearchDirection(researchId);

        // 返回导师列表为 JSON 数据
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().write(new Gson().toJson(mentors));
    }
}
